﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.FactoryManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.FactoryManagement.EncodeSchemeVMs
{
    public partial class EncodeSchemeListVM : BasePagedListVM<EncodeScheme_View, EncodeSchemeSearcher>
    {
        
        protected override IEnumerable<IGridColumn<EncodeScheme_View>> InitGridHeader()
        {
            return new List<GridColumn<EncodeScheme_View>>{
                
                this.MakeGridHeader(x => x.EncodeScheme_Name).SetTitle(@Localizer["Page.方案名称"].Value),
                this.MakeGridHeader(x => x.EncodeScheme_Code).SetTitle(@Localizer["Page.方案代号"].Value),
                this.MakeGridHeader(x => x.EncodeScheme_FormName).SetTitle(@Localizer["Page.表单名称"].Value),
                this.MakeGridHeader(x => x.EncodeScheme_FormCode).SetTitle(@Localizer["Page.表单代码"].Value),
                this.MakeGridHeader(x => x.EncodeScheme_SerialNumber).SetTitle(@Localizer["Page.当前流水号"].Value),
                this.MakeGridHeader(x => x.EncodeScheme_Remark).SetTitle(@Localizer["Page.备用"].Value),
                this.MakeGridHeader(x => x.EncodeScheme_Active).SetTitle(@Localizer["Page.激活"].Value),
                this.MakeGridHeader(x => x.EncodeScheme_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.EncodeScheme_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.EncodeScheme_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.EncodeScheme_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<EncodeScheme_View> GetSearchQuery()
        {
            var query = DC.Set<EncodeScheme>()
                
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckContain(Searcher.Code, x=>x.Code)
                .CheckContain(Searcher.FormName, x=>x.FormName)
                .CheckContain(Searcher.FormCode, x=>x.FormCode)
                .CheckEqual(Searcher.SerialNumber, x=>x.SerialNumber)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .CheckEqual(Searcher.Active, x=>x.Active)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new EncodeScheme_View
                {
				    ID = x.ID,
                    
                    EncodeScheme_Name = x.Name,
                    EncodeScheme_Code = x.Code,
                    EncodeScheme_FormName = x.FormName,
                    EncodeScheme_FormCode = x.FormCode,
                    EncodeScheme_SerialNumber = x.SerialNumber,
                    EncodeScheme_Remark = x.Remark,
                    EncodeScheme_Active = x.Active,
                    EncodeScheme_CreateTime = x.CreateTime,
                    EncodeScheme_UpdateTime = x.UpdateTime,
                    EncodeScheme_CreateBy = x.CreateBy,
                    EncodeScheme_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class EncodeScheme_View: EncodeScheme
    {
        
        public string EncodeScheme_Name { get; set; }
        public string EncodeScheme_Code { get; set; }
        public string EncodeScheme_FormName { get; set; }
        public string EncodeScheme_FormCode { get; set; }
        public long? EncodeScheme_SerialNumber { get; set; }
        public string EncodeScheme_Remark { get; set; }
        public bool? EncodeScheme_Active { get; set; }
        public DateTime? EncodeScheme_CreateTime { get; set; }
        public DateTime? EncodeScheme_UpdateTime { get; set; }
        public string EncodeScheme_CreateBy { get; set; }
        public string EncodeScheme_UpdateBy { get; set; }

    }

}